package com.core.web.struts2.taglib;

import org.apache.struts2.views.jsp.*;

import javax.servlet.jsp.*;

/**
 * TextArea JSP 标签
 * 
 * 
 */
public class TextAreaTag extends CommonTag {

	protected String cols;
	protected String rows;
	protected String wrap;

	@Override
	public int doStartTag() throws JspException {
		return SKIP_BODY;
	}

	@Override
	public int doEndTag() throws javax.servlet.jsp.JspException {
		try {
			pageContext.getOut().print(getHtml());
		} catch (Exception e) {
			throw new JspException(e);
		}
		return EVAL_BODY_INCLUDE;
	}

	private String getHtml() {
		StringBuffer ret = new StringBuffer();

		StringBuffer tmpTag = new StringBuffer(super.getCommonHtml());

		if (this.cols != null && !this.cols.equals("")) {
			tmpTag.append(" cols=\"").append(this.cols).append("\"");
		}
		if (this.rows != null && !this.rows.equals("")) {
			tmpTag.append(" rows=\"").append(this.rows).append("\"");
		}
		if (this.wrap != null && !this.wrap.equals("")) {
			tmpTag.append(" wrap=\"").append(this.wrap).append("\"");
		}

		Object stackObject = TagUtils.getStack(this.pageContext)
				.findValue(name);
		String inputValue = "";

		if (getValue() != null && !getValue().equals("")) {
			inputValue = getValue();
		}
		if (stackObject != null && !stackObject.equals("")) {
			inputValue = stackObject.toString();
		}

		ret.append("<textarea ").append(tmpTag.toString()).append(" >").append(
				inputValue).append("</textarea>");
		return ret.toString();
	}

	public String getCols() {
		return cols;
	}

	public void setCols(String cols) {
		this.cols = cols;
	}

	public String getRows() {
		return rows;
	}

	public void setRows(String rows) {
		this.rows = rows;
	}

	public String getWrap() {
		return wrap;
	}

	public void setWrap(String wrap) {
		this.wrap = wrap;
	}
}
